//
//  RHLocalParamSetVC.m
//  RuiHeAppApp
//
//  Created by Yan Chen on 2024/4/9.
//

#import "RHLocalParamSetVC.h"
#import "JXCategoryView.h"
#import "JXCategoryListContainerView.h"
#import "RHLocalParamSetListVC.h"
#import "RHLocalSettingTypeModel.h"
#import "CBLECenterMnger.h"

@interface RHLocalParamSetVC ()<JXCategoryListContainerViewDelegate,JXCategoryViewDelegate,JXCategoryTitleViewDataSource>

@property (nonatomic, strong) NSArray *titles;

@property (nonatomic, strong) JXCategoryTitleView *categoryView;

@property (nonatomic, strong) JXCategoryListContainerView *listContainerView;

//端点类型数组
@property (nonatomic ,strong) NSArray *typeArray;



@end

@implementation RHLocalParamSetVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"参数设置".rh_localized;
    [self.view setBackgroundColor:CFTabViewBgColor];
    [self createTypeArray];
    [self setupUI];
   
}


- (void)setupUI{
    
    _listContainerView = [[JXCategoryListContainerView alloc] initWithType:JXCategoryListContainerType_ScrollView delegate:self];
    [self.view addSubview:self.listContainerView];
    
    _categoryView = [[JXCategoryTitleView alloc] initWithFrame:CGRectMake(0,0, [UIScreen mainScreen].bounds.size.width, 50)];
    self.categoryView.titles = self.titles;
    self.categoryView.backgroundColor = [UIColor whiteColor];
    self.categoryView.delegate = self;
    self.categoryView.cellWidth = JXCategoryViewAutomaticDimension;
    self.categoryView.titleSelectedColor = CMainColorGreen;
    self.categoryView.titleColor = kCOLOR_HEX(@"969799");
    self.categoryView.titleFont = [UIFont systemFontOfSize:14];
    self.categoryView.titleSelectedFont = [UIFont boldSystemFontOfSize:14];
    self.categoryView.titleColorGradientEnabled = YES;
    self.categoryView.titleLabelZoomEnabled = NO;
    self.categoryView.titleLabelZoomScale = 1.0;
    self.categoryView.cellSpacing = 20;
//    self.categoryView.contentEdgeInsetLeft = 50;
//    self.categoryView.contentEdgeInsetRight = 50;
    self.categoryView.titleLabelVerticalOffset = -10;
    [self.view addSubview:self.categoryView];
    self.categoryView.listContainer = self.listContainerView;
    
    JXCategoryIndicatorBackgroundView *backgroundView = [[JXCategoryIndicatorBackgroundView alloc] init];
//     backgroundView.size = CGSizeMake(60, 3);
     backgroundView.indicatorColor = CMainColorGreen;
     backgroundView.indicatorHeight = 3;
//     backgroundView.indicatorWidth = 60;
     backgroundView.verticalMargin = -10;
     backgroundView.indicatorCornerRadius = 1.5;

     _categoryView.indicators = @[backgroundView];
    
    
    [_categoryView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_offset(0);
        make.top.mas_offset(0);
        make.height.mas_equalTo(50);
    }];
    
    [_listContainerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_offset(0);
        make.top.equalTo(self.categoryView.mas_bottom).offset(0);
        make.bottom.mas_offset(0);
    }];
    
}

-(void)createTypeArray
{
    //有主控
    if ([CBLECenterMnger shareMnger].curPheral.hasMaster) {
        self.typeArray = @[@(LocalSettingType_EMS),@(LocalSettingType_Master),@(LocalSettingType_Pack1)];
        self.titles = @[@"EMS",@"Master",@"Pack"];
        if ([CBLECenterMnger shareMnger].curPheral.isHighVoltage) {//纳通高压去掉pack
            self.typeArray = @[@(LocalSettingType_EMS),@(LocalSettingType_Master)];
            self.titles = @[@"EMS",@"Master"];
        }
    }else{
       //没有主控
        self.typeArray = @[@(LocalSettingType_EMS),@(LocalSettingType_Pack1)];
        self.titles = @[@"EMS",@"Pack"];
    }
}


#pragma mark - JXCategoryViewDelegate

// 点击选中或者滚动选中都会调用该方法。适用于只关心选中事件，不关心具体是点击还是滚动选中的。
- (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
    NSLog(@"%@", NSStringFromSelector(_cmd));
    // 侧滑手势处理
    self.navigationController.interactivePopGestureRecognizer.enabled = (index == 0);
    
    
}

// 滚动选中的情况才会调用该方法
- (void)categoryView:(JXCategoryBaseView *)categoryView didScrollSelectedItemAtIndex:(NSInteger)index {
    NSLog(@"%@", NSStringFromSelector(_cmd));
}

#pragma mark - JXCategoryListContainerViewDelegate
// 返回列表的数量
- (NSInteger)numberOfListsInlistContainerView:(JXCategoryListContainerView *)listContainerView {
    return  self.titles.count;
}

// 返回各个列表菜单下的实例，该实例需要遵守并实现 <JXCategoryListContentViewDelegate> 协议
- (id<JXCategoryListContentViewDelegate>)listContainerView:(JXCategoryListContainerView *)listContainerView initListForIndex:(NSInteger)index {

    RHLocalParamSetListVC *setVC = [[RHLocalParamSetListVC alloc]init];
    setVC.settingType = (LocalSettingType)[self.typeArray[index] integerValue];
    return setVC;
    
  
}



@end
